import mindspore
from mindspore import Tensor, nn
from mindspore import dtype
import numpy as np


def init_network():
    network = {}
    network['w1'] = Tensor(np.random.normal(0, 1, [3, 2]), dtype.float32)
    network['b1'] = Tensor(np.random.normal(0, 1, [3]), dtype.float32)
    network['w2'] = Tensor(np.random.normal(0, 1, [3, 3]), dtype.float32)
    network['b2'] = Tensor(np.random.normal(0, 1, [3]), dtype.float32)
    network['w3'] = Tensor(np.random.normal(0, 1, [2, 3]), dtype.float32)
    network['b3'] = Tensor(np.random.normal(0, 1, [2]), dtype.float32)
    return network


class Net(nn.Cell):
    def __int__(self):
        # super(Net, self).__init__()
        super(self).__init__()
        network = init_network()
        w1, w2, w3 = network['w1'], network['w2'], network['w3']
        b1, b2, b3 = network['b1'], network['b2'], network['b3']
        self.fc1 = nn.Dense(2, 3, w1, b1, True, 'sigmoid')
        self.fc2 = nn.Dense(3, 3, w2, b2, True, 'sigmoid')
        self.fc3 = nn.Dense(3, 2, w3, b3, True)


    def construct(self, x):
        x = self.fc1(x)
        x = self.fc2(x)
        x = self.fc3(x)
        return x


input = Tensor(np.array([[1.0, 2.0]]), dtype.float32)
model = Net()

model.construct(input)
output = model(input)
print(output)
